package logic.login_logic;


import datasv.datafactorysv.LoginDatasvFactory;
import datasv.login_datasv.LoginDatasv;
import datasv.login_datasv.LoginDatasvController;
import logicsv.login_logicsv.UserType;
import po.UserPO;
import resultmessage.LoginRM;
import stub.datasvStub.LoginDatasvStub;

public class Login {
	private String id;
	private String password;
	private  UserType userType;
	private LoginDatasv loginData;
//	private LoginDatasv loginData = new LoginDatasvStub(new UserPO("121250143", "121250143"));
	public Login(String id, String password){
		this.id = id;
		this.password = password;
		LoginDatasvFactory ldf = new LoginDatasvFactory();
		loginData = ldf.create();
		userType = UserType.getUserType(id);
	}
	/**return the id type*/
	public UserType getUserType(){
		return userType;
	}
//	/**judge whether the password is formatted
//	 * @return true the password is formatted
//	 * 				false the password is not formatted
//	 * */
//	public boolean formattedPwd(){
//		PasswordFormat pf = new PasswordFormat();
//		return pf.formatted(password);
//	}
	/** use the id and password user has input to login
	 * @return ResultMessage an enum about the login result
	 * */
	public LoginRM login() {
		UserPO user = loginData.findUser(id);
		if(user == null){
			return LoginRM.NO_EXIST_ID;
		}
		if(user.getPassword().equals(password)){
			return LoginRM.SUCCESS;
		}else{
			return LoginRM.WRONG_PASSWORD;
		}
	}
	public static void main(String[] args){
		Login logger1 = new Login("121250143","112");
		System.out.println(logger1.login());
		Login logger2 = new Login("121250143","121250143");
		System.out.println(logger2.login());
		Login logger3 = new Login("1250143","121250143");
		System.out.println(logger3.getUserType());
	}
//	protected static ResultMessage judgeResult(String id,String password){
//		return judge(id, password);
//	}
//	private static ResultMessage judge(String id,String password){
//		UserPO po=new UserPO("123456","123456");
//		if(po.getID().equals("123456")&&po.getPassword().equals("123456")){
//			return ResultMessage.SUCCESS;
//		}
//		return ResultMessage.NO_EXIST_ID;
//	} 
////	public Identity get
}
